package com.uuj.dome.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ClassName:SessionInterceptor
 * PACKAGE_NAME:com.uuj.dome.interceptor
 */
public class SessionInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {


        if (request.getRequestURI().equals("/user/login") || request.getRequestURI().equals("/user/login_view")) {
            return true;
        }

        Object user = request.getSession().getAttribute("user");
        if (user == null) {
            // 跳转登录页面
            response.sendRedirect("/user/login_view");
            return false;
        }


        return true;
    }



}
